package module3;

public class StringTest {

    public static void main(String[] args) {
        String str = new String("ABCD123!@#$%ab");
        char[] cha1 = str.toCharArray();
        for (int i = 0; i < cha1.length; i++){
            System.out.println("数组中第" + (i+1) + "个数值是：" + cha1[i]);
        }
        System.out.println("--------------------------------------------------");
        /*int j = 0;
        for (char i: cha1) {
            j++;
            System.out.println("数组中第" + j + "个元素是：" + i);
        }*/
        System.out.println("--------------------------------------------------");

        int[] ia = new int[4];
        int p = 0;
        for (char j: cha1) {
            p++;
            String str2 = String.valueOf(cha1[p-1]);
            if(str2.matches("[A-Z]")) {
                ia[0]++;
            }else if(str2.matches("[a-z]")) {
                ia[1]++;
            }else if(str2.matches("[0-9]")) {
                ia[2]++;
            }else ia[3]++;
        }
        System.out.println("大写字母的个数统计结果是：" + ia[0] );
        System.out.println("小写字母的个数统计结果是：" + ia[1] );
        System.out.println("数字个数的统计结果是：" + ia[2]);
        System.out.println("其他字符的个数统计结果是：" + ia[3]);
    }
}
